package com.lagou.springbootjob.web;

import com.lagou.springbootjob.model.ArticleDO;
import com.lagou.springbootjob.repository.ArticleRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * 博客列表入口
 * @author helenlee
 * @date 2020-05-17 03:04:38
 */
@Controller
public class ArticleController {
    @Resource
    private ArticleRepository articleRepository;
    @RequestMapping
    public String index(Model model
            , @RequestParam(value = "pageNum",defaultValue = "0")Integer pageNum
            ,@RequestParam(value = "pageSize",defaultValue = "2")Integer pageSize){
        Page<ArticleDO> articles = articleRepository.findAll(PageRequest.of(pageNum, pageSize, Sort.by("id")));
        model.addAttribute("articles",articles);
        return "index";
    }
}
